<?php


require_once($INCLUDE_PATH . 'include/AppConf.php');


abstract class AppController
{
  public static $conf;
  public function __construct()
  {
    global $INCLUDE_PATH;
    self::$conf = new AppConf($INCLUDE_PATH . 'conf/base.ini.php');

    // load controller's own configuration file by controller name
    // if this configuration file is not exist, then we just ignore this line
    self::$conf->add($INCLUDE_PATH . 'conf/' . Y::$controller . '/base.ini.php');
    self::$conf->add($INCLUDE_PATH . 'conf/' . Y::$controller . '/'.Y::$action.'.ini.php');
 
  }

  public function setPageHeader($charset = "utf-8")
  {

    header('Content-type: text/html; charset='.$charset);

    // TODO: maybe here we should put more settings in default header setting
  }
  public function confValue($sectionName, $itemName)
  {
    return self::$conf->confValue($sectionName, $itemName);
  }
   function actionDefault()
  {
  }
  public static function sysMessage($msg,$urls = array()) {
    $urlList  = array();
    Y::$tpl->set("message",$msg);
    if(empty($urls)) {
      $urlList['返回上一页']  = 'javascript:history.go(-1)';
    }
    else {
      foreach ($urls as $k=>$v) {
        if(empty($k)) {
          $k  = '返回上一页';
        }
        if(preg_match("/javascript/iS", $v) || $v == 'GOBACK') {
          $urlList[$k]  = 'javascript:history.go(-1);';
        }
        else {
          $urlList[$k]  = $v;
        }
      }
    }
    if(preg_match("/javascript/iS", current($urlList))){
      $autourl  = current($urlList);
    }
    else {
      $autourl  = "window.location.href =\'".current($urlList)."\';";
    }
    Y::$tpl->set("urlList",$urlList);
    Y::$tpl->set("autourl",$autourl);
    Y::$htmlFile = 'redirect_msg.html';

    return false;
  }
}
?>
